package www.lagou.app;

/**
 * 手机表查询
 */

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayHandler;
import org.junit.Test;
import www.lagou.utils.DruidUtils;
import java.sql.SQLException;
import java.util.Arrays;

public class SearchPhone {
    /**
     *查询价格高于2000元，生产日期是2019年之前的所有手机
     * @throws SQLException
     */
    @Test
    public  void searchByPrice() throws SQLException {
        QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());
        String sql = "SELECT * FROM phone WHERE price > 2000 AND prodate > '2019-0-0';";
        Object[] query = queryRunner.query(sql, new ArrayHandler());
        System.out.println(Arrays.toString(query));
    }

    /**
     * 查询所有颜色是白色的手机信息
     * @throws SQLException
     */
    @Test
    public void searchByColor() throws SQLException {
        QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());
        String sql = "select * from phone where color = '白色';";
        Object[] query = queryRunner.query(sql, new ArrayHandler());
        System.out.println(Arrays.toString(query));
    }


}
